package com.totalinlink.dsl.poi.wrappers

import com.totalinlink.dsl.poi.WorkBookBuilder

/**
 * Created by wangguangyu on 15/5/24.
 */
class ForStyleWrapper extends NodeWrapper {

    // name of cell style
    def name
    // workbook wrapper
    def workbook
    // styleWrapper
    def style
    // cellWrapper
    def cell

    @Override
    void syncNode() {
        cell.style = style
        cell.poiObject.setCellStyle(style.poiObject)
    }

    ForStyleWrapper(WorkBookBuilder workBookBuilder, Map attributes) {
        super(workBookBuilder, attributes)

        workbook = workBookBuilder.workbook
        name = attributes.style
        style = workbook.namedStyles[name]
        def rowNo, cellNo
        (rowNo, cellNo) = attributes.pos
        def row = workBookBuilder.curSheet.getRow(rowNo)
        cell = row.getCell(cellNo)
        if (!cell) {
            cell = new CellWrapper(workBookBuilder, [value: null, parent: row, index: cellNo, style: style])
            row.cells << cell
        }
    }

    @Override
    def void setNode(child) {
        return
    }
}
